'''
Created on May 11, 2012

@author: nicole

Contains the necessary methods for a cross validation test
'''
from random import shuffle

def crossvalid(k, dataset):
    "Divides the dataset in k random subsets, and generates the rotated train and test combinations "
   
    shuffle(dataset)
    
    sets = [dataset[i::k] for i in xrange(k)]
    for i in range(k):
        test = sets[i]
        print(test)
        training = [item
                    for s in sets if s is not test
                    for item in s]
        yield training,test
        
